package com.joolun.web.controller.mall;

import java.util.List;

import com.joolun.mall.entity.TbWork;
import com.joolun.mall.service.ITbWorkService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;

import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * workController
 * 
 * @author www.joolun.com
 * @date 2023-02-17
 */
@RestController
@RequestMapping("/system/work")
public class TbWorkController extends BaseController
{
    @Autowired
    private ITbWorkService tbWorkService;

    /**
     * 查询work列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbWork tbWork)
    {
        startPage();
        List<TbWork> list = tbWorkService.selectTbWorkList(tbWork);
        return getDataTable(list);
    }

    /**
     * 导出work列表
     */
    @PreAuthorize("@ss.hasPermi('system:work:export')")
    @Log(title = "work", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbWork tbWork)
    {
        List<TbWork> list = tbWorkService.selectTbWorkList(tbWork);
        ExcelUtil<TbWork> util = new ExcelUtil<TbWork>(TbWork.class);
        return util.exportExcel(list, "work");
    }

    /**
     * 获取work详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbWorkService.selectTbWorkById(id));
    }

    /**
     * 新增work
     */
    @PreAuthorize("@ss.hasPermi('system:work:add')")
    @Log(title = "work", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbWork tbWork)
    {
        return toAjax(tbWorkService.insertTbWork(tbWork));
    }

    /**
     * 修改work
     */
    @PreAuthorize("@ss.hasPermi('system:work:edit')")
    @Log(title = "work", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbWork tbWork)
    {
        return toAjax(tbWorkService.updateTbWork(tbWork));
    }

    /**
     * 删除work
     */
    @PreAuthorize("@ss.hasPermi('system:work:remove')")
    @Log(title = "work", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbWorkService.deleteTbWorkByIds(ids));
    }
}
